package com.project.cris.SessionBean;
import java.util.ArrayList;

import javax.persistence.EntityManager;
import javax.persistence.Query;


import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.PersistenceContext;



import com.project.entity.PropForRent;

@Stateless
@LocalBean
public class Search_PropForRentBean implements Search_PropForRentRemote {
	@PersistenceContext
	EntityManager em;
	@Override
	public ArrayList<PropForRent> getAllPropForRent() throws Exception {
		// TODO Auto-generated method stub
		Query query = em.createNamedQuery("PropForRent.findAllPropForRent");
		@SuppressWarnings("unchecked")
		ArrayList<PropForRent> result = (ArrayList<PropForRent>) query.getResultList();
		return result;
	}
	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<PropForRent> searchPropForRent(String title,String address,String state,double depositMin,double depositMax,double rentMin,double rentMax,int bedroomMin,int bedroomMax,int bathroomMin,int bathroomMax) throws Exception {
		Query query=em.createNamedQuery("PropForRent.searchPropForRent");
		
		query.setParameter("address", "%"+address+"%");
		
		query.setParameter("depositMin", depositMin);
		query.setParameter("depositMax", depositMax);
		query.setParameter("rentMin", rentMin);
		query.setParameter("rentMax", rentMax);
		query.setParameter("bedRoomMin", bedroomMin);
		query.setParameter("bedRoomMax", bedroomMax);
		query.setParameter("bathRoomMin", bathroomMin);
		query.setParameter("bathRoomMax", bathroomMax);
		 return (ArrayList<PropForRent>) query.getResultList();
		
	}
	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<PropForRent> ListPrices(double min, double max) {
		Query query=em.createQuery("select pro from PropForRent pro where pro.deposit between :min and :max");
		query.setParameter("min", min);
		query.setParameter("max", max);
		return (ArrayList<PropForRent>) query.getResultList();
	}
	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<PropForRent> advanceSearch(double depositMin,
			double depositMax, double rentMin, double rentMax, int bedroomMin,
			int bedroomMax, int bathroomMin, int bathroomMax) {
		Query query=em.createNamedQuery("PropForRent.searchAdvance");
		query.setParameter("depositMin", depositMin);
		query.setParameter("depositMax", depositMax);
		query.setParameter("rentMin", rentMin);
		query.setParameter("rentMax", rentMax);
		query.setParameter("bedRoomMin", bedroomMin);
		query.setParameter("bedRoomMax", bedroomMax);
		query.setParameter("bathRoomMin", bathroomMin);
		query.setParameter("bathRoomMax", bathroomMax);
		 return (ArrayList<PropForRent>) query.getResultList();
		
	}
	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<PropForRent> simpleSearch(String title, String address) {
		Query query=em.createNamedQuery("PropForRent.searchSimple");
		query.setParameter("title", "%"+title+"%");
		query.setParameter("address", "%"+address+"%");
		 return (ArrayList<PropForRent>) query.getResultList();
	}

	
	
	
	

}
